package com.junzhiit.nengji.cms.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.JsonUtil;
import com.junzhiit.nengji.cms.service.ChainGoodsSkuService;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsSkuContentVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.model.ChainGoodsSkuItems;
import com.junzhiit.nengji.model.ChainSkuContent;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/chain/goodssku")
public class ChainGoodsSkuController extends BaseController{
	
	@Autowired
	private ChainGoodsSkuService chainGoodsSkuService;

	@ApiOperation(value = "获取商品相关sku_items")
	@RequestMapping(value = "/skuitems/{chainGoodsId}", method = RequestMethod.GET)
	public ResultVO queryGoodsSkuItems(@PathVariable String chainGoodsId) {
		return chainGoodsSkuService.queryGoodsSkuItems(chainGoodsId);
	}
	
	@ApiOperation(value = "获取商品相关SKU名称和规格")
	@RequestMapping(value = "/skuitems/bo/{chainGoodsId}", method = RequestMethod.GET)
	public ResultVO queryGoodsSkuItemsBO(@PathVariable String chainGoodsId){
		return chainGoodsSkuService.queryGoodsSkuItemsBO(chainGoodsId);
	}
	
	@ApiOperation(value = "获取商品规格组合内容")
	@RequestMapping(value = "/skucontent/{chainGoodsId}", method = RequestMethod.GET)
	public ResultVO querySkuContent(@PathVariable String chainGoodsId) {
		return chainGoodsSkuService.querySkuContent(chainGoodsId);
	}

	@ApiOperation(value = "保存商品规格组合")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(ChainGoodsSkuContentVO chainGoodsSkuContentVO) {
		String chainGoodsSkuItemses = chainGoodsSkuContentVO.getChainGoodsSkuItemses();
		String chainSkuContents = chainGoodsSkuContentVO.getChainSkuContents();
		String chainGoodsId = chainGoodsSkuContentVO.getChainGoodsId();

		List<ChainGoodsSkuItems> chainGoodsSkuItemlist = JsonUtil.toListObject(chainGoodsSkuItemses, ChainGoodsSkuItems.class);
		List<ChainSkuContent> chainSkuContentlist = JsonUtil.toListObject(chainSkuContents, ChainSkuContent.class);

		return chainGoodsSkuService.addGoodsSku(chainSkuContentlist, chainGoodsSkuItemlist, chainGoodsId);
	}

	@ApiOperation(value = "查询商品相关skuContent")
	@RequestMapping(value = "/goodsid", method = RequestMethod.GET)
	public Map<String, Object> findAllByGoodsId(String chainGoodsId, DataTablesParamVO dtp) {
		return chainGoodsSkuService.findAllByGoodsId(chainGoodsId, dtp);
	}
	
}
